#include "cor.hpp"

void foo2(Schedule *s, void *para) {
    int* arg = static_cast<int*>(para);
    for(int i = 0; i < 5; i++) {
        printf("%d \n",  *arg + i);
        s->yield_cor();
    }
}

void foo(Schedule *s, void *para) {
    int* arg = static_cast<int*>(para);
    int b = 1000;
    int co2id = s->create_cor(foo2, &b);
    for(int i = 0; i < 5; i++) {
        s->resume_cor(co2id);
        printf("%d \n",  *arg + i);
        s->yield_cor();
    }
    while (s->cors[co2id]->state != DEAD)
        s->resume_cor(co2id);
    
}

int main()
{
    auto s = make_shared<Schedule>();
    int a = 0;
    int b = 100;
    int co1id = s->create_cor(foo, &a);
    
    printf("main start.\n");

    while(!s->all_finished())
        s->resume_cor(co1id);

    printf("main end.\n");
    return 0;
}